<?php
/**
 * Created by PhpStorm.
 * User: gaojie
 * Date: 16/8/2
 * Time: 下午4:58
 */

namespace app\Http\Controllers;

use App\Http\Controllers;
use App\Model\Site;
use App\Model\Warn;
use Illuminate\Http\Request;
use App\Library\Helper;
use App\Model\Device;

class WarnController extends Controller{

    public function postCreateWarn(Request $request){
        $param = $request->all();
        $site_id=$request->input('site_id');
        $site=Site::find($site_id);
        $param['user_id']=$site->user_id;
        $param['read'] = 3;
        $param['invert_or'] = $param['invert_status'];
        $param['invert_status'] = dechex($param['invert_status']);
        $obj=Warn::Create($param);
        if($site->id == 36 || $site_id == 40){
            if ($param['invert_status'] == '1015') {
                $this->_sendAlert('15990545251', $site->name, '无电网故障');
            }
            if ($param['invert_status'] == '1039') {
                $this->_sendAlert('15990545251', $site->name, '漏电流自检保护故障');
            }

        }else {
            $arrs = ['13566333595', '13567416656', '13738800853', '15258265988', '18368665217'];
            foreach ($arrs as $arr) {
                if ($param['invert_status'] == '1015') {
                    $this->_sendAlert($arr, $site->name, '无电网故障');
                }
                if ($param['invert_status'] == '1039') {
                    $this->_sendAlert($arr, $site->name, '漏电流自检保护故障');
                }
            }
        }

            if (!$obj) {
                return $this->json_sys_error();
            }
            return $this->json_success();

    }


}